package com.assignwork.vo;

import com.assignwork.util.BigDecimalSerializer;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.NullSerializer;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class WorkArrangeShipMobileVO {

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;
    @JsonSerialize(using = ToStringSerializer.class)
    private Long assemblyLineId;
    @JsonSerialize(using = ToStringSerializer.class)
    private Long planId;
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    private LocalDateTime startTime;
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    private LocalDateTime endTime;
    private String cargoType;
    private String cargoTypeName;
    private String packageBulk;
    private String packageBulkName;
    private String workerInfo;
    private String craneInfo;
    private String forkliftInfo;
    private String tractorInfo;
    private String loaderInfo;
    private String excavatorInfo;
    private String cabinName;
    private String planCabinName;
    @JsonSerialize(using = BigDecimalSerializer.class, nullsUsing = NullSerializer.class)
    private BigDecimal planTon;
    private Integer isAudit;

    private List<WorkArrangeShipCabinInfoVO> cabinList;
    private List<WorkArrangeShipUnderMachineVO> underMachineList;
    private List<StartedCabinVO> planCabinList;

    public String getPlanCabinName() {
        if (Func.isNotEmpty(planCabinList)) {
            return planCabinList
                    .stream()
                    .filter(i -> Func.isNotBlank(i.getCabinName()))
                    .map(StartedCabinVO::getCabinName)
                    .collect(Collectors.joining("\\"));
        }
        return planCabinName;
    }

    public BigDecimal getPlanTon() {
        if (Func.isNotEmpty(cabinList)) {
            return cabinList
                    .stream()
                    .filter(i -> i.getPlanTon() != null)
                    .map(WorkArrangeShipCabinInfoVO::getPlanTon)
                    .collect(Collectors.reducing(BigDecimal.ZERO, BigDecimal::add));
        }
        return planTon;
    }
}
